<template>
  <div id="banner">
    <div class="banner">
      <swiper :options="swiperOption" ref="mySwiper">
        <swiper-slide v-for="(slide, index) in swiperSlides" :key="index">
          <img :src="slide.thumb" alt style="width:100%;height:100%;display:block;" />
        </swiper-slide>
        <div class="swiper-pagination" slot="pagination"></div>
      </swiper>
      <div class="swiper-Btn-next" ref="mySwiper_next"></div>
      <div class="swiper-Btn-prev" ref="mySwiper_prev"></div>
    </div>
  </div>
</template>
<script>
import "swiper/dist/css/swiper.css";
import {getBanner,getTradeshowsInland} from "../../api/home";

export default {
  name: "carrousel",
  data() {
    return {
      swiperOption: {
        autoplay: true,
        loop: true,
        // direction: "vertical",
        loopFillGroupWithBlank: true,
        pagination: {
          el: ".swiper-pagination",
          clickable: true,
          bulletClass: "my-pagination", //需设置.my-bullet样式
          bulletActiveClass: "my-pagination-active"
        },
        navigation: {
          nextEl: ".swiper-Btn-next",
          prevEl: ".swiper-Btn-prev"
        }
      },
      swiperSlides: []
    };
  },
  computed: {
    swiper() {
      return this.$refs.mySwiper.swiper;
    }
  },
  mounted() {
    let _this = this;
    // 调用computed里面的swiper方法
    _this.swiper.el.onmouseover = function() {
      _this.swiper.autoplay.start();
    };
    _this.$refs.mySwiper_next.onmouseover = function() {
      _this.swiper.autoplay.start();
    };
    _this.$refs.mySwiper_prev.onmouseover = function() {
      _this.swiper.autoplay.start();
    };

    /**
     * 获取轮播图
     */
    getBanner().then(res => {
      this.swiperSlides = res.data.data;
    })
  }
};
</script>

<style lang="scss" scoped>
.banner {
  // padding: 60px 14px;
  width: 720px;
  // height: 390px;
  position: relative;
  .swiper-container {
    width: 100%;
    // height: 100%;
    .swiper-wrapper {
      .swiper-slide {
        text-align: center;
        font-size: 18px;
        background: #fff;
        /* Center slide text vertically */
        display: -webkit-box;
        display: -ms-flexbox;
        display: -webkit-flex;
        display: flex;
        -webkit-box-pack: center;
        -ms-flex-pack: center;
        -webkit-justify-content: center;
        justify-content: center;
        -webkit-box-align: center;
        -ms-flex-align: center;
        -webkit-align-items: center;
        align-items: center;
      }
    }
    .swiper-pagination {
      position: absolute;
      text-align: center;
      -webkit-transition: 300ms opacity;
      -o-transition: 300ms opacity;
      transition: 300ms opacity;
      -webkit-transform: translate3d(0, 0, 0);
      transform: translate3d(0, 0, 0);
      z-index: 10;
      .my-bullet {
        background: #626262;
        border: 1px solid #e5e2e2;
        // opacity: 1;
        width: 8px;
        height: 8px;
        display: inline-block;
        border-radius: 100%;
        background: #000;
        opacity: 0.2;
        margin: 0 4px;
        cursor: pointer;
      }
      .my-bullet-active {
        background: #e5e2e2;
        border: 1px solid #e5e2e2;
        opacity: 1;
      }
    }
    .swiper-pagination-fraction,
    .swiper-pagination-custom,
    .swiper-container-horizontal > .swiper-pagination-bullets {
      bottom: 10px;
      left: 0;
      width: 100%;
    }
  }

  .swiper-Btn-next,
  .swiper-Btn-prev {
    position: absolute;
    z-index: 10;
    width: 24px;
    height: 50px;
    text-align: center;
    //   line-height: 30px;
    //   font-size: 24px;
    top: 50%;
    margin-top: -25px;
    cursor: pointer;
    background-size: 100%;
    background-repeat: no-repeat;
  }
  .swiper-Btn-prev {
    left: 0;
    background-image: url("../../assets/banner_prev.png");
  }
  .swiper-Btn-next {
    right: 0;
    background-image: url("../../assets/banner_next.png");
  }
}
</style>